import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home,
    redirect:'/index',
    children:[
      {
        path: '/index',
        name: 'index',
        meta:{
          title:'微博 - 首页',
        },
        component: () => import('../views/index.vue')
      },
      {
        path: '/login',
        name: 'login',
        meta:{
          title:'微博 - 登录',
        },
        component: () => import('../views/login.vue')
      },
      {
        path: '/register',
        name: 'register',
        meta:{
          title:'微博 - 注册',
        },
        component: () => import('../views/register.vue')
      },
      {
        path: '/mySpace',
        name: 'mySpace',
        meta:{
          title:'微博 - 我的空间',
        },
        component: () => import('../views/mySpace.vue')
      },
      {
        path: '/square',
        name: 'square',
        meta:{
          title:'微博 - 广场',
        },
        component: () => import('../views/square.vue')
      },
      {
        path: '/set',
        name: 'set',
        meta:{
          title:'微博 - 设置',
        },
        component: () => import('../views/set.vue')
      },
    ]
  },
]

const router = new VueRouter({
  routes
})

//每页标题
router.beforeEach((to,from,next)=>{
  console.log('beforeEach',to,from);
  if(to.meta.title){
    document.title=to.meta.title;
  }else{
    document.title='无名'
  }
  next();
})

// const router = new VueRouter({
//   mode: 'history',
//   base: process.env.BASE_URL,
//   routes
// })

export default router